import Vue from 'vue'
import Vuex from 'vuex'
import { setSessionStorageItem, getSessionStorageItem } from '@/Storage/storage'

Vue.use(Vuex)

const TOUTIAO_USER = 'TOUTIAO_USER'

export default new Vuex.Store({
  state: {
    userToken: getSessionStorageItem(TOUTIAO_USER)
  },
  mutations: {
    setUser(state,userToken){
      // 保存userToken
      state.userToken = userToken
      // 调用函数用sessionStorage将userToken持久化
      setSessionStorageItem(TOUTIAO_USER,userToken)
    }
  },
  actions: {
  },
  modules: {
  }
})
